<?php
namespace Admin\Controller;
use Think\Controller;
class UserController extends CommonController {


	//用户列表
    public function userList(){

        C('TOKEN_ON',false);
        
        $userModel=M("user");

        $map=I("get.");
        if($map["secuname"]){
            $where["username"]=array("like","%".$map["secuname"]."%");
        }
        $comList=getPages($userModel,$where);        
        $this->assign("userList",$comList["comList"]);
        $this->assign("page",$comList["page"]);

        $this->display();
    }
    //用户新增
    public function addUser(){

        $this->display();
    }

    //用户修改
    public function updUser(){
        
        $id=I("get.id");
        if($id > 0){
            $user=D("user")->getUserById($id);   
            $this->assign("user",$user);
            $this->display();

        }else{
            $this->error("参数错误");
        }
        
    }
    //ajax删除用户
    public function ajaxDelUser(){

        $map=I("post.ids");

        $arr['code'] = 100;
        $arr['info'] = "删除失败";

        if(IS_AJAX && $map) {
            
            //拆分id
            $data=explode(",",$map);

            $userModel=D("user");
            $res=$userModel->delData($data);

            if($res>0){
                $arr['code'] = 200;
                $arr['info'] = "删除成功";
            }
        };
        $this->ajaxReturn($arr);

    }
    //用户新增/修改-提交表单
    public function editUserForm(){
        

        $data=I("post.");

        $userModel=D("user");
        $res=$userModel->editData($data);
        if($res){
            $this->success();
        }else{
            $this->error($userModel->getError(),$_SERVER['HTTP_REFERER']);
        }

    }
    
    //充值明细
    public function rechargeRecord(){

        $this->display();
    }
}